<template>
	<!--  -->
	<view class="content">
		<block v-if="currentComponent=='userCenter'">

		</block>
		<block v-else>
			<block v-if="currentComponent=='indexHome'||currentComponent=='task'
			 ||currentComponent=='message' 
			   
			  ">
				<uni-nav-bar fixed class="navtop" statusBar :title="title">
				</uni-nav-bar>
			</block>
			<block v-else>
				<uni-nav-bar left-icon="back" class="navtop" fixed @clickLeft="clickLeft" statusBar :title="title">
					<view slot="left">
						<view @click="setCurrentPage(0)" class="iconfont icon-index icon-index-my">

						</view>
					</view>
				</uni-nav-bar>
			</block>
		</block>
		<!-- 组件 页面 start-->
		<!-- 首页 start -->
		<view class="" v-show="currentComponent=='indexHome'">
			<indexHome @handleSignature="handleSignature"></indexHome>
		</view>
		<!-- 首页 end -->
		<view class="">
			<taskDetail v-if="currentComponent=='taskDetail'" @sumbitProject="sumbitProject" @goContract="goContract">
			</taskDetail>
		</view>
		<view class="">
			<!-- 查看合同 -->
			<readContract v-if="currentComponent=='readContract'" @goUserSignature="goUserSignature"></readContract>
		</view>
		<view class="">
			<!-- 签名 -->
			<userSignature v-if="currentComponent=='userSignature'"></userSignature>
		</view>
		<view class="">
			<!--  -->
			<task :currentHeight="currentHeight" v-show="currentComponent=='task'"></task>
		</view>
		<view class="">
			<!-- 消息-->
			<message v-show="currentComponent=='message'"></message>
		</view>
		<view class="">
			<!-- 我的-->
			<userCenter @goUserdetail="goUserdetail" @handleContract="handleContract"
				@handleCommission="handleCommission" @handleSetBankCard="handleSetBankCard"
				@handleAccount="handleAccount" v-show="currentComponent=='userCenter'"></userCenter>
		</view>
		<view class="">
			<!-- 个人信息 -->
			<userdetail @goRealName="goRealName" v-if="currentComponent=='userdetail'"></userdetail>
		</view>
		<view class="">
			<!-- 我的合同 -->
			<myContract v-if="currentComponent=='myContract'"></myContract>
		</view>
		<view class="" v-if="currentComponent=='checkProjectInfo'">
			<checkProjectInfo></checkProjectInfo>
		</view>
		<!-- 我的佣金 -->
		<myCommission v-if="currentComponent=='myCommission'"></myCommission>
		<!-- 银行卡认证-->
		<setBankCard v-if="currentComponent=='setBankCard'"></setBankCard>
		<!-- 实名认证 -->
		<setRealName v-if="currentComponent=='setRealName'"></setRealName>
		<!-- 账户设置 -->
		<account v-if="currentComponent=='account'"></account>
		<!-- 组件 页面 end-->
		<view class="" v-show="currentComponent!='userCenter'" style="height: 120rpx;"></view>
		<view class="btnNav">
			<bottomTabBar :currentIndex="currentIndex" @change="currentIndexChage">
			</bottomTabBar>
		</view>
	</view>
</template>
<script>
	let context = null;
	export default {
		data() {
			return {
				currentHeight: 0,
				currentNavHeight: "",
				pageArr: [1, 1, 1], //首页任务 消息的分页处理
				currentComponent: "myCommission",
				currentIndex: 0, //底部导航
				taskId: 0, //任务详情id
				readContractId: "", //合同id
				title: "实名认证"
			}
		},
		onLoad(opt) {
			// this.currentIndex = opt.index ? opt.index : this.currentIndex
			// uni.setStorageSync('currentIndex', this.currentIndex) //写入底部导航
			// this.setCurrentPage(this.currentIndex)

		},
		onReady() {

			
			// 不要动 start
			const query = uni.createSelectorQuery().in(this);
			query.select('.navtop').boundingClientRect(data => {
				this.currentHeight = data.height
				this.currentNavHeight = data.height
				const query1 = uni.createSelectorQuery().in(this);
				query1.select('.btnNav').boundingClientRect(data1 => {
					this.currentHeight += data1.height
					uni.getSystemInfo({
						success: (res) => {
							this.currentHeight = res.screenHeight - this.currentHeight;
							this.currentHeight -= uni.upx2px(82)
							console.log(this.currentHeight);
						}

					})
				}).exec();
			}).exec();
			// 不要动 end
		},
		onBackPress(e) {
			console.log("监听返回按钮事件", this.clickLeft);
			//   // 此处一定姚要return为true，否则页面不会返回到指定路径
			return true;
		},
		methods: {
			clickLeft() {
				let item = this.getRouter()
				console.log(item);
				if (Array.isArray(item)) {
					this.setCurrentPage(this.currentIndex)
				} else {
					this.currentComponent = item.name
					this.title = item.title
				}
			},
			setCurrentPage(index) {
				if (index == 0) {
					this.currentComponent = "indexHome"
					this.title = "任务大厅"

				} else
				if (index == 1) {
					this.currentComponent = "task"
					this.title = "任务"
				} else
				if (index == 2) {
					this.currentComponent = "message"
					this.title = "消息"
				} else
				if (index == 3) {
					this.currentComponent = "userCenter"
				}
				this.currentIndex = index
				uni.setStorageSync('routerName', []) //写入路由
			},
			/**
			 * @param {Object}item name路由名字 title路由导航标题
			 */
			setRouter(item) {
				let routers = uni.getStorageSync('routerName') ? uni.getStorageSync('routerName') : [];
				routers.push(item)
				uni.setStorageSync('routerName', routers) //写入路由
			},
			/**
			 * @param  获取上一级
			 */
			getRouter() {
				let name = {}
				let routers = uni.getStorageSync('routerName') ? uni.getStorageSync('routerName') : [];
				if (routers.length == 1) {
					name = routers
				} else {
					routers.pop()
					uni.setStorageSync('routerName', routers) //写入路由
					name = routers[routers.length - 1]
				}

				return name;
			},
			/**
			 * @param {Object} e 任务id
			 */
			handleSignature(e) {
				// if(!this.$login.isLogin()) return
				this.currentComponent = "taskDetail";

				this.title = "任务详情"
				this.setRouter({
					name: this.currentComponent,
					title: this.title
				})
				this.taskId = e;
			},

			/**
			 * 我的佣金
			 */
			handleCommission() {
				this.currentComponent = "myCommission";
				this.title = "我的佣金"
				this.setRouter({
					name: this.currentComponent,
					title: this.title
				})
			},
			/**
			 * 银行卡认证
			 */
			handleSetBankCard() {
				this.currentComponent = "setBankCard";
				this.title = "银行卡认证"
				this.setRouter({
					name: this.currentComponent,
					title: this.title
				})
			},
			handleAccount() {
				this.currentComponent = "account";
				this.title = "账户设置"
				this.setRouter({
					name: this.currentComponent,
					title: this.title
				})
			},
			/**
			 * 实名认证
			 */
			goRealName() {
				this.currentComponent = "setRealName";
				this.title = "实名认证"
				this.setRouter({
					name: this.currentComponent,
					title: this.title
				})
			},

			/**
			 * 我的合同
			 */
			handleContract() {
				this.currentComponent = "myContract";
				this.title = "我的合同"
				this.setRouter({
					name: this.currentComponent,
					title: this.title
				})
			},
			/**
			 * @param {Object} e提交验收材料
			 */
			sumbitProject() {
				this.currentComponent = "checkProjectInfo";
				this.title = "验收详情"
				this.setRouter({
					name: this.currentComponent,
					title: this.title
				})
			},
			/**
			 * 查看合同
			 */
			goContract(e) {
				this.currentComponent = "readContract";
				this.title = "查看合同"
				this.setRouter({
					name: this.currentComponent,
					title: this.title
				})
				this.readContractId = e;
			},
			/**
			 * 用户签字
			 */
			goUserSignature(e) {
				this.currentComponent = "userSignature";
				this.title = "用户签字"
				this.setRouter({
					name: this.currentComponent,
					title: this.title
				})
			},
			/**
			 * 个人信息
			 */
			goUserdetail(e) {
				this.currentComponent = "userdetail";
				this.title = "个人信息"
				this.setRouter({
					name: this.currentComponent,
					title: this.title
				})
			},
			currentIndexChage(e) {
				this.currentIndex = e.index
				this.setCurrentPage(e.index)
				uni.setStorageSync('currentIndex', this.currentIndex) //写入底部导航
			},

		}
	}
</script>

<style lang="scss">
	.btnNav {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 750rpx;
		z-index: 3;
	}

	.icon-index-my {
		font-size: 43rpx;
		font-weight: bold;
		margin-bottom: 8rpx;
	}
</style>
